import { Message } from 'element-ui';
import { request } from '../../common/request.js';
import { setCookie } from '../../common/utils.js';
import axios from 'axios';
export default {

    data() {
        return {
            username: 'admin',
            password: 'admin01',
        }
    },

    components: {},

    computed: {

    },
    methods: {
        sub() {
            let self = this,
                jn = self.username,
                pd = self.password;
            if (!jn || !pd) {
                Message({
                    showClose: true,
                    message: '账号和密码必须完整',
                    type: 'error'
                });
                return;
            }

            // 测试用的token ，后期if作用域删掉
            if (process.env.NODE_ENV == 'development') {
              setCookie('token_code', '822076c8-ac95-4467-b379-295655f11e11|1', 10);
              this.$router.push('/index');

              return false;
            }

            request({
                url: 'Login',
                data: {
                    username: this.username,
                    password: this.password
                }
            }).then(res => {
                if (res && res.message) {
                    setCookie('token_code', res.message, 1);
                    this.$router.push('/index');
                }
            })
            
        }
    },
    mounted(){
        let _this = this;
        _this.name = "";
        _this.password = "";
    }
}
